package com.tanhua.dubbo.server.api;

import com.alibaba.dubbo.config.annotation.Service;
import com.tanhua.dubbo.server.pojo.Vioce;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

@Slf4j
@Service(version = "1.0.0")
public class PeachBlossomApiImpl implements PeachBlossomApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public Boolean saveVoice(Long userId, String url) {
        Vioce vioce = new Vioce();
        try {
            vioce.setId(new ObjectId());
            vioce.setSoundUrl(url);
            vioce.setUserId(userId);
            vioce.setCreated(System.currentTimeMillis());
            mongoTemplate.save(vioce);
        } catch (Exception e) {
            log.error("储存失败" + vioce, e);
        }
        return true;
    }
}
